Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[선재] WEEK02 Solutions #341

Merged
merged 7 commits into from
Aug 25, 2024
Merged

[선재] WEEK02 Solutions #341

merged 7 commits into from
Aug 25, 2024

Conversation

Sunjae95
Copy link
Contributor

@Sunjae95 Sunjae95 commented Aug 18, 2024

1주차 피드백 추가

@DaleSeo @YeonguChoe 두분 피드백 내용 적용했습니다.
@DaleSeo님 피드백 받을 때 제 컴퓨터환경이 끊기면서 듣게돼서 달레님 의도와 다르게 적용했을수도 있을거 같아 코멘트 남깁니다.
두분의 리뷰를 코드에 적용해보니 결국 https://www.algodale.com/problems/palindromic-substrings/ 의 3번째 솔루션으로 가는걸 발견했습니다.
피드백 감사합니다 :)

@Sunjae95 Sunjae95 self-assigned this Aug 18, 2024
Comment on lines +109 to +115
let subStr = "";
let isSubPalindromic = true;
answer++;

for (let endIndex = startIndex + 1; endIndex < len; endIndex++) {
if (isSubPalindromic && s[startIndex] === s[endIndex]) answer++;
subStr += s[endIndex];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaleSeo
slice를 하지말고 마지막을 추가하면서 계산하라는 말씀이 이 부분이 맞을까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제 피드백을 약간 잘못 이해하신 것 같습니다. 저는 아래에 있는 isPalindromic() 함수에 대해서 말씀을 드렸어요. 이 함수가 부분 문자열을 인자로 받는 대신에 시작 인덱스와 종료 인덱스를 받게 변경하면 공간 복잡도를 O(n)에서 O(1)로 개선할 수 있을 것 같다는 의견을 드렸습니다. 현재 코드는 여전히 O(n)의 공간을 쓰는 것으로 보입니다. 왜냐하면 subStr 변수에 최대 n개의 글자가 저장될 수 있기 때문입니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇.. 그렇군요! 이 부분은 다시 고민해보겠습니다 ㅎㅎ

Comment on lines +152 to +160
while (s[start] === s[end] && start >= 0 && end < len) {
count++;
[start, end] = [start - 1, end + 1];
}
[start, end] = [i, i + 1];
while (s[start] === s[end] && start >= 0 && end < len) {
count++;
[start, end] = [start - 1, end + 1];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YeonguChoe
kadane's 알고리즘을 검색해보니 부분합이이라는 것을 알게 됐네요. 적용하다보니 달레님 블로그 솔루션 3번으로 귀결됐습니다 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나이스샷!

@Sunjae95 Sunjae95 added the js label Aug 18, 2024
Copy link
Contributor

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모임 때 받으셨던 피드백에 대해서 고민해보시는 모습이 멋있습니다!

Comment on lines +109 to +115
let subStr = "";
let isSubPalindromic = true;
answer++;

for (let endIndex = startIndex + 1; endIndex < len; endIndex++) {
if (isSubPalindromic && s[startIndex] === s[endIndex]) answer++;
subStr += s[endIndex];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제 피드백을 약간 잘못 이해하신 것 같습니다. 저는 아래에 있는 isPalindromic() 함수에 대해서 말씀을 드렸어요. 이 함수가 부분 문자열을 인자로 받는 대신에 시작 인덱스와 종료 인덱스를 받게 변경하면 공간 복잡도를 O(n)에서 O(1)로 개선할 수 있을 것 같다는 의견을 드렸습니다. 현재 코드는 여전히 O(n)의 공간을 쓰는 것으로 보입니다. 왜냐하면 subStr 변수에 최대 n개의 글자가 저장될 수 있기 때문입니다.

@Sunjae95 Sunjae95 marked this pull request as ready for review August 23, 2024 09:29
Comment on lines +10 to +15
* result:
* 1. couldn't think of the conditions
* true: 1~9, 10~27
* false: 0, 0N, 28↑
* 2. persist solution that is top down
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당부분은 직접 풀어보려 시도했지만 풀지 못한관계로 알고달레 블로그 참고해서 작성했습니다.

@Sunjae95 Sunjae95 reopened this Aug 23, 2024
@Sunjae95 Sunjae95 added js and removed js labels Aug 23, 2024
@Sunjae95 Sunjae95 marked this pull request as draft August 23, 2024 21:45
@Sunjae95 Sunjae95 marked this pull request as ready for review August 23, 2024 21:45
Copy link
Contributor

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

valid-anagram/sunjae95.js Show resolved Hide resolved
Comment on lines +20 to +42
preorder.forEach((val, i) => {
const node = new TreeNode(val);

if (i === 0) answer = node;

const leftLen = leftStack.length;
const rightLen = rightStack.length;

if (leftLen && rightLen) {
if (leftStack[leftLen - 1].left) rightStack[rightLen - 1].right = node;
else leftStack[leftLen - 1].left = node;
}
if (leftLen && !rightLen) leftStack[leftLen - 1].left = node;
if (!leftLen && rightLen) rightStack[rightLen - 1].right = node;

leftStack.push(node);

while (leftStack.length && pointer < inorder.length) {
if (leftStack[leftStack.length - 1].val !== inorder[pointer]) break;
rightStack.push(leftStack.pop());
pointer++;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굉장히 멋진 풀이네요!

@DaleSeo DaleSeo requested a review from jaejeong1 August 24, 2024 00:24
@Sunjae95 Sunjae95 added the js label Aug 24, 2024
@DaleSeo DaleSeo merged commit dfd73f6 into DaleStudy:main Aug 25, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants